用户<template>
	<view class="content">
		<view class="headeruser-image">
			<image src="/static/images/background.png">
		</view>
		<view class="flex-center main-body">
			<view class="login-box">
				<view class="flex-center login-box-logo">
					<view class="logo-out flex-center">
						<view class="logo-box flex-center">
							<image class="logo" src="../../static/images/logo.png"></image>
						</view>
					</view>
				</view>
				<view class="inp-box-frame flex-center">
					<view class="inp-box-inner flex-center">
						<view class="inp-box-content flex-center">
							<view class="inp">
								<u--input v-model="username" placeholder="账号" prefixIcon="account-fill"
									prefixIconStyle="font-size: 22px;color: #5b5b5b">
								</u--input>
							</view>
							<view class="inp">
								<u--input v-model="password" placeholder="密码" prefixIcon="lock-fill"
									prefixIconStyle="font-size: 22px;color: #5b5b5b" type="password">
								</u--input>
							</view>
							<view class="but-box">
								<u-row gutter="50">
									<u-col :span="6">
										<u-button type="primary" text="登录" @click="login"></u-button>
									</u-col>
									<u-col :span="6">
										<u-button type="primary" :plain="true" text="注册" @click="register"></u-button>
									</u-col>
								</u-row>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="box-tit" @click="jumpIcu">
				ICU配置工具
			</view>
		</view>
		<u-modal :show="show" title="用户协议以及隐私政策" confirmText='同意并继续' @confirm="agreeConfirm">
			<u-toast ref="uToast" />
			<view style="width: 100%">
				<p class='content-text'>您需要同意用户协议与隐私协议政策后才能使用该小程序。如您不同意,很遗憾我们无法为您提供服务。</p>
				<p class='content-text' style='margin-top: 35rpx;'></p>
				<p class='content-text' style='margin-top: 35rpx;'>您可以阅读<text @click="userGree">《用户协议》</text>和
					<text @click="prvacyPol">《隐私协议》</text>了解详细信息。如你同意请点击“同意并继续”开始接受我们的服务。
				</p>
				<p class='content-text' style='margin-top: 35rpx;margin-bottom: 55rpx;'>
					我们深知个人信息对您的重要性,我们将严格遵守有关法律法规,并采取相应的重要保护技术措施，尽力保护您的个人信息安全。在使用小程序的过程中，我们会基于您的授权获取您的以下权限，您有权拒绝。
				</p>
			</view>
		</u-modal>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				show: false,
				title: '123',
				ceshi: '111',
				das: 56,
				username: '',
				password: '',
				//是否已经获取用户信息
				hasUserInfo: false,
				//是否可以调用获取信息得函数
				canIUseGetUserProfile: false,
			};
		},
		mounted() {
			//uni.clearStorageSync()
			let usernameShow = uni.getStorageSync('username')
			let passwordShow = uni.getStorageSync('password')
			if (usernameShow && passwordShow) {
				this.username = usernameShow
				this.password = passwordShow
				this.login()
				this.show = false
			} else {
				this.show = true
			}
		},
		methods: {
			jumpIcu() {
				uni.navigateTo({
					url: '../configure/configure'
				})
			},
			/* getUserProfile: function(e) {
				wx.getUserProfile({
					desc: '获取您的微信个人信息',
					success: (res) => {
						this.setData({
							hasUserInfo: true
						})
						var app = getApp()
						app.globalData.userInfo = res.userInfo; // 将用户信息存到globalData里面
					},
					fail: function(e) {
						wx.showToast({
							title: '你选择了取消',
							icon: "none",
							duration: 1500,
							mask: true
						})
					}
				})
			}, */
			login() {
				this.$post('/security/auth/login', {
					username: this.username,
					password: this.password
				}).then(res => {
					if (res.code == 200) {
						uni.setStorageSync('username', res.data.username)
						uni.setStorageSync('password', this.password)
						uni.setStorageSync('userId', res.data.userId)
						uni.setStorageSync('token', res.data.token)
						uni.setStorageSync('profilePicture', res.data.profilePicture)
						uni.setStorageSync('userData', res.data)
						uni.reLaunch({
							url: '/pages/index/index'
						});
						// 隐藏小房子返回主页
						uni.hideHomeButton()
					} else {
						uni.$u.toast(res.message)
					}

				})
			},
			register() {
				uni.navigateTo({
					url: '../register/register'
				})
			},
			userGree() {
				uni.navigateTo({
					url: '../useragreement/useragreement'
				})
			},
			prvacyPol() {
				uni.navigateTo({
					url: '../privacypolicy/privacypolicy'
				})
			},
			agreeConfirm() {
				this.show = false
			},

		},
		onShareAppMessage: function() {

		},
	}
</script>

<style lang="scss" scoped>
	.box-tit {
		position: absolute;
		bottom: 50rpx;
		color: #2f2f2f;
	}

	.flex-center {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: wrap;
	}

	.content {
		width: 750rpx;
		height: 100%;
		position: relative;
	}

	.headeruser-image {
		width: 750rpx;
		height: 100%;
		position: absolute;
		z-index: 0;
	}

	.headeruser-image>image {
		width: 100%;
		height: 100%;
	}

	.main-body {
		width: 750rpx;
		height: 100%;
		position: absolute;
		z-index: 1;
		align-items: flex-start;
	}

	.login-box {
		width: 600rpx;
		height: 750rpx;
		align-items: flex-start;
		position: relative;
		top: 300rpx;
	}

	.login-box-logo {
		width: 600rpx;
		height: 200rpx;
		position: absolute;
		z-index: 3;
	}

	.inp-box-frame {
		width: 600rpx;
		height: 600rpx;
		position: absolute;
		z-index: 2;
		top: 100rpx;
		/* border: 2px dashed #FFFFFF; */
		border-radius: 40rpx;
	}

	.logo-out {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
		/* border: 2px dashed #f3f3f3; */
	}

	.logo-out>.logo-box {
		width: 180rpx;
		height: 180rpx;
		border-radius: 50%;
		background-color: #5cabf8;
	}

	.inp-box-inner {
		width: 580rpx;
		height: 500rpx;
		border-radius: 40rpx;
		background-color: rgba(255, 255, 255, 0.6);
	}

	.inp {
		width: 500rpx;
	}

	.but-box {
		width: 500rpx;
		height: 60rpx;
	}

	.inp-box-content {
		width: 580rpx;
		height: 400rpx;
	}

	.logo {
		width: 100rpx;
		height: 100rpx;
	}

	text {
		color: #007AFF;
	}
</style>
